package com.yangcangclub.trade.utils;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.net.URL;
import java.net.URLConnection;

public class HttpUtils {

	public static String postXmlString(String postUrl, String xml)
			throws Exception {
		String res = "";
		try {
			URL url = new URL(postUrl);
			URLConnection con = url.openConnection();
			con.setDoOutput(true);
			con.setRequestProperty("Pragma:", "no-cache");
			con.setRequestProperty("Cache-Control", "no-cache");
			con.setRequestProperty("Content-Type", "text/xml");

			OutputStreamWriter out = new OutputStreamWriter(
					con.getOutputStream());
			out.write(xml);
			out.flush();
			out.close();
			BufferedReader br = new BufferedReader(new InputStreamReader(
					con.getInputStream()));
			String line ;
			for (line = br.readLine(); line != null; line = br.readLine()) {
				res += line;
			}
			System.out.println("res:" + res);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return res;
	}

}